<% feature_for(:export_pdf) do %>
<div class="box export-repository-pdf mb-section">
  <div class="box-header">
    <h1 class="title mb-3">
      <div class="content"><%= t(".Export as PDF") %></div>
      <div class="text-gray f5">
        <%= t(".You can export all docs as a PDF file") %>
      </div>
    </h1>
  </div>
  <div class="box-body">
    <% if Rails.env.development? %>
    <div class="mb-3">
      <%= link_to t(".Preview PDF HTML"), repository.to_path("/settings/export?type=pdf"), class: "btn-link", target: "_blank" %>
    </div>
    <% end %>

    <div class="text-gray-light mb-2">
      <%= t(".Exporter will use the TOC ordered, otherwice same as the") %> <%= link_to t(".Doc list"), repository.to_path("/docs/list"), target: "_blank", class: "link-gray-dark" %>.
    </div>

    <% if repository.export_pdf_status == "running" %>
      <div class="pdf-export-running">
        <p><%= icon_tag("loading") %> <%= t(".PDF has in generating, please wait") %></p>
        <p style="display: none" class="pdf-export-retry-message text-gray">
          <%= raw t(".If you are waiting a long time, you can retry", retry: link_to("retry", repository.to_path("/settings/export?type=pdf&force=1"), method: "post", remote: true)) %>
        </p>
      </div>
      <script type="text/javascript">
        // sleep 5s to check status
        window.checkPDFExportStatus = setInterval(function() {
          $.post("<%= repository.to_path("/settings/export?type=pdf&check=1") %>");
        }, 5000);

        // timeout in 25s showup retry message.
        setTimeout(function() {
          $(".pdf-export-retry-message").fadeIn();
        }, 25000);

        // clean timer after page exit
        document.addEventListener("turbolinks:before-cache", () => {
          clearInterval(window.checkPDFExportStatus);
        });
      </script>
    <% elsif repository.pdf.attached? %>
      <div class="pdf-export-exist">
        <p><%= t(".PDF of this repository was generated") %></p>
        <p><%= t(".Click the button to download it") %></p>
        <div class="form-group">
          <%= link_to t(".Download"), repository.export_url(:pdf), target: "_blank", class: "btn btn-download-pdf btn-primary" %>
          <%= link_to t(".Generate Again"), repository.to_path("/settings/export?type=pdf&force=1"), class: "btn btn-regenerate-pdf", method: :post, remote: true, "disable-with": t(".Submiting") %>
        </div>
      </div>
      <script type="text/javascript">
        clearInterval(window.checkPDFExportStatus);
      </script>
    <% else %>
      <div class="pdf-export-generate">
        <div class="text-gray mb-3"><%= icon_tag("warn") %> <%= t(".Generate PDF will take a long time") %></div>
        <div class="form-group">
          <%= link_to t(".Generate PDF"), repository.to_path("/settings/export?type=pdf&force=1"), class: "btn btn-primary btn-submit btn-generate-pdf", method: :post, remote: true, "disable-with": t(".Submiting") %>
        </div>
      </div>
    <% end %>
  </div>
</div>
<% end %>